package com.kun.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.kun.entity.User;
import com.kun.service.IUserRedisService;

@RestController
public class RedisDemoController {
    
    @Autowired
    private IUserRedisService userRedisService;
    
    @RequestMapping("/addUsers")
    public String addUsers(){
        List<User> users = new ArrayList<User>();
        for (int i = 0; i < 20; i++) {
            User user = new User();
            user.setId(i+"");
            user.setPhone(i+"");
            user.setUsername("张三"+i);
            users.add(user);
        }
        userRedisService.saveUsers(users);
        return "添加完成。";
    }
    
    @RequestMapping("/findAll")
    public List<User> findAll(){
        return userRedisService.findAll();
    }
    
    @RequestMapping(value="/findUser/{id}",method={RequestMethod.GET})
    public User findUser(@PathVariable String id){
        return userRedisService.findById(id);
    }
}